package com.community.zhihuishequ.utils;

import android.Manifest;
import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Build;
import android.support.v4.app.ActivityCompat;

import com.blankj.utilcode.util.PhoneUtils;

/**
 * Created by Rick on 18/2/22.
 *
 */

public class PhoneUtil {
    public static String getImei(Context context) {
        String imei = "";
        try {
            // 小于android 6.0不用考虑权限问题
            if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1) {
                if (ActivityCompat.checkSelfPermission(context, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
                    imei = PhoneUtils.getIMEI();
                } else {
                    imei = "没有权限获取IMEI";
                }
            } else {
                imei = PhoneUtils.getIMEI();
            }
        } catch (Throwable e) {
            e.printStackTrace();
        }
        return imei;
    }
}
